<?php

/**
 * @package    Base_List
 * @subpackage UnitTests
 */


/**
 * Base_List
 */
require_once 'Base/List.php';

/**
 * PHPUnit Test Case
 */
require_once 'PHPUnit/Framework/TestCase.php';


/**
 * @package    Base_List
 * @subpackage UnitTests
 *
 */
class Base_ListTest extends PHPUnit_Framework_TestCase
{
	protected $list = null;
	
	public function setup()
	{
		$this->list = new Base_List();
	}
	
	public function testAttach()
	{
		$this->list->attach('a');
		$this->list->attach('b');
		$this->list->attach('c', 'key');
		$this->assertEquals('a', $this->list->get(0));
		$this->assertEquals('b', $this->list->get(1));
		$this->assertEquals('c', $this->list->get('key'));
	}

	public function testPrepend()
	{
		/*
		 * Prepend will reset all numeric keys for every new element that is
		 * prepened.
		 */
		$this->list->prepend('a');
		$this->assertEquals('a', $this->list->get(0));
		$this->list->prepend('b');
		$this->assertEquals('b', $this->list->get(0));
		$this->list->prepend('c');
		$this->assertEquals('c', $this->list->get(0));
	}

	public function testRemove()
	{
		$this->list->attach('a');
		$this->list->attach('b');
		$this->list->attach('c', 'key');

		$this->assertEquals(3, count($this->list));

		$this->list->remove(0);
		$this->list->remove(1);
		$this->list->remove('key');

		$this->assertEquals(0, count($this->list));
	}
	
	public function testGet()
	{
		$this->list->attach('a');
		$this->list->attach('b', 'key');
		
		$this->assertEquals('a', $this->list->get(0));
		$this->assertEquals('b', $this->list->get('key'));
		
		$gotException = false;
		try
		{
			$this->list->get('key_test');
		}
		catch (Base_List_Exception $oE)
		{
			$gotException = true;
		}
		$this->assertTrue($gotException);
	}
}
